package com.wmwj.hxlj.controller;

import com.wmwj.hxlj.entity.Article;
import com.wmwj.hxlj.entity.User;
import com.wmwj.hxlj.entity.vo.ArticleVo;
import com.wmwj.hxlj.entity.vo.UserVo;
import com.wmwj.hxlj.service.ArticleService;
import com.wmwj.hxlj.service.UserService;
import com.wmwj.hxlj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private UserService userService;

    //通过文章关键词搜索文章
    @GetMapping("/articles")
    public Result<List<ArticleVo>> searchArticles(@RequestParam String keyword,@RequestParam Integer pageStart) {
        return articleService.searchArticles(keyword, pageStart);
    }

    @GetMapping("/{userAccount}")
    public Result<List<UserVo>> searchUsersByAccount(@RequestParam String account) {
        return userService.searchUsersByAccount(account);
    }

    //通过标签名称搜索文章
    @GetMapping("/articlesByTag")
    public Result<List<ArticleVo>> searchArticlesByTag(@RequestParam String tagName) {
        return articleService.searchArticlesByTag(tagName);
    }

    //通过分类id搜索文章
    @GetMapping("/articlesByCategoryId")
    public Result<List<ArticleVo>> searchArticlesByCategoryId(@RequestParam Long categoryId,@RequestParam Integer pageStart) {
        return articleService.searchArticlesByCategoryId(categoryId,  pageStart);
    }

}
